﻿using System;
using Model;
using Resources;
using Service;


public partial class warrantyModify : System.Web.UI.Page
{
    readonly StockService _StockService = new StockService();
    EquipPurchaseInfo _PurchaseInfo = new EquipPurchaseInfo();

    protected void Page_Load(object sender, EventArgs e)
    {
        SetVisibleMode();
        
    }
    protected void btnValidate_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["purchaseId"] != "0")
        {
            _PurchaseInfo = GetEquipPurchaseInfo(Int32.Parse(Request.QueryString["purchaseId"]));
            _StockService.InsertPurchaseInfo(_PurchaseInfo);
        }
    }
    private EquipPurchaseInfo GetEquipPurchaseInfo(int purchaseId)
    {
        EquipPurchaseInfo equipmentPurchaseInfo = _StockService.GetPurchaseInfo(purchaseId);
        equipmentPurchaseInfo.ContractDescription = txtContractDescription.Text;
        equipmentPurchaseInfo.IsWarranty = chkIsWarranty.Checked;
        equipmentPurchaseInfo.StartDate = !txtStartDate.DateValue.ToShortDateString().Equals(Resource.EmptylDateTime) ? DateTime.Parse(txtStartDate.DateValue.ToShortDateString()) :
                   DateTime.Parse(Resource.DateTimeNull);
        equipmentPurchaseInfo.EndDate = !txtEndDate.DateValue.ToShortDateString().Equals(Resource.EmptylDateTime) ? DateTime.Parse(txtStartDate.DateValue.ToShortDateString()) :
                   DateTime.Parse(Resource.DateTimeNull);
        
        
        return equipmentPurchaseInfo;
    }
    protected void chkIsWarranty_CheckedChanged(object sender, EventArgs e)
    {
        SetVisibleMode();
    }
    private void SetVisibleMode()
    {
        txtContractDescription.Enabled = chkIsWarranty.Checked;
        txtStartDate.Enabled = chkIsWarranty.Checked;
        txtEndDate.Enabled = chkIsWarranty.Checked;
        btnValidate.Enabled = chkIsWarranty.Checked;
    }
}
